﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WHC.OrderWater.Commons;


namespace WHC.Hotel.UI
{
    public partial class FrmEditDiscount : BaseForm
    {
        public FrmEditDiscount()
        {
            InitializeComponent();
        }

        private void txtDiscountPrice_TextChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtDiscountPrice.Text) && ValidateUtil.IsNumeric(txtDiscountPrice.Text))
            {
                decimal oldPrice = Convert.ToDecimal(this.txtPrice.Text);
                decimal discountPrice = Convert.ToDecimal(this.txtDiscountPrice.Text);
                if (oldPrice > 0 && discountPrice > 0)
                {
                    txtDiscountRate.Text = (discountPrice / oldPrice).ToString("f2");
                }
                else
                {
                    txtDiscountRate.Text = "0";
                }
            }
        }

        private void txtDiscountRate_TextChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtDiscountRate.Text) && ValidateUtil.IsNumeric(txtDiscountRate.Text))
            {
                decimal oldPrice = Convert.ToDecimal(this.txtPrice.Text);
                decimal discountRate = Convert.ToDecimal(this.txtDiscountRate.Text);
                if (oldPrice > 0 && discountRate > 0)
                {
                    txtDiscountPrice.Text = (discountRate * oldPrice).ToString("f2");
                }
                else
                {
                    txtDiscountPrice.Text = "0";
                }
            }
        }

        private void FrmEditDiscount_Load(object sender, EventArgs e)
        {
            this.txtDiscountPrice.Focus();
        }
    }
}
